package com.shen.computer;



/**
 * Author:shen
 * CreateDate:2020/5/17.
 * Function:
 */
public class MainBoard {
    private String name;
    private CPU cpu;// 插槽
    private Memory mem;// 内存插槽
    private KeyboardService keyboardService;//键盘
    // 4个usb插口
    private USB[] usbs = new USB[4];

    public MainBoard(String n) {
        name = n;
    }


    public void work() {
        System.out.println("主板是:" + name);
        System.out.println("cpu开始:");
        cpu.calculate();
        System.out.println("检测键盘：");
        keyboardService.keyboardLink();
        System.out.println("内存开始:");
        mem.work();
        for (int i = 0; i < usbs.length; i++) {
            if (usbs[i] != null)
                usbs[i].work();
        }

    }

    // 安装cpu
    public void assembleCPU(CPU c) {
        this.cpu = c;
    }

    // 安装内存
    public void installMem(Memory m) {
        this.mem = m;
    }

    // 插上usb设备
    public void installUSB(USB u) {
        for (int i = 0; i < usbs.length; i++) {
            if (usbs[i] == null) {
                usbs[i] = u;
                usbs[i].plug();
                return;
            }
        }
    }
    //检测键盘
    public void installKeyboard(KeyboardService keyboardService){
        this.keyboardService=keyboardService;
    }
}
